﻿using DeviceState.Model;
using System;
using System.Collections.Generic;
using System.Text;

namespace DeviceState.DAL
{
    public class DeviceDAL
    {
        public bool UpdatNtpServer(string ntp)
        {
            string strSql = "UPDATE devinfo SET ntpserver='" + ntp + "'";
            CommFN<DevInfo> fn = new CommFN<DevInfo>();
            return fn.ExecFN(strSql);
        }

        public bool InsertIncar(Incarevents incarevents)
        {
            try
            {
                string strSql = string.Format("INSERT into incarevents (UUID,credenctype,operatetype,cmdtime,result,reason,ttrAMA2_data,ttrAMA3_data) VALUES('{0}',{1},{2},'{3}','{4}','{5}','{6}','{7}')"
                    , incarevents.UUID, incarevents.credenctype, incarevents.operatetype, incarevents.cmdtime, incarevents.result, incarevents.reason, incarevents.ttrAMA2_data, incarevents.ttrAMA3_data);
                CommFN<Incarevents> fn = new CommFN<Incarevents>();
                return fn.ExecFN(strSql);
            }
            catch
            {
                return false;
            }
        }

        public bool InsertOutcar(Outcarevents outcarevents)
        {
            try
            {
                string strSql = string.Format("INSERT into outcarevents(cmd,cmdtime,result,reason,ttrAMA1_data,ttrAMA3_data)VALUES('{0}','{1}','{2}','{3}','{4}','{5}')"
                    , outcarevents.cmd, outcarevents.cmdtime, outcarevents.result, outcarevents.reason, outcarevents.ttrAMA1_data, outcarevents.ttrAMA3_data);
                CommFN<Incarevents> fn = new CommFN<Incarevents>();
                return fn.ExecFN(strSql);
            }
            catch
            {
                return false;
            }
        }

        public bool InsertModeRecord(ModeRecord modeRecord)
        {
            try
            {
                string strSql = string.Format("INSERT into workmoderecord(workmode,updatetime,reason)VALUES({0},'{1}','{2}')"
                    , modeRecord.workmode, modeRecord.updatetime, modeRecord.reason);
                CommFN<ModeRecord> fn = new CommFN<ModeRecord>();
                return fn.ExecFN(strSql);
            }
            catch
            {
                return false;
            }
        }

        public bool InsertEquipment(Equipment equipment)
        {
            try
            {
                string strSql = string.Format("INSERT into equipment_operation(devtype,state,actiontime,reason)VALUES('{0}',{1},'{2}','{3}')"
                    , equipment.devtype, equipment.state, equipment.actiontime, equipment.reason);
                CommFN<Equipment> fn = new CommFN<Equipment>();
                return fn.ExecFN(strSql);
            }
            catch
            {
                return false;
            }
        }
    }
}
